package me.andy.superappsorganizer.model;

import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;

public class DataOrganizer {

	Context context;
	private String where;
	public DataOrganizer(Context context) {
		this.context=context;
	}
	
	public void DumpAll() {
		context.getContentResolver().delete(SuperAppsOrganizerProvider.CONTENT_URI, null, null);
	}
	
	public void loadData() {
		
		final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
		mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
		final List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
		
		ContentValues appsData = new ContentValues();
		for (ResolveInfo rInfo : pkgAppsList) {
			
			appsData.put(SAppsDatabase.COL_APP_TITLE, rInfo.activityInfo.packageName);
			context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
		}
		
		/*Integer i=0;
        ContentValues appsData = new ContentValues();
        appsData.put(SAppsDatabase.COL_APP_TITLE, "test:"+(++i).toString());
        context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
        appsData.put(SAppsDatabase.COL_APP_TITLE, "test:"+(++i).toString());
        context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
        appsData.put(SAppsDatabase.COL_APP_TITLE, "test:"+(++i).toString());
        context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
        appsData.put(SAppsDatabase.COL_APP_TITLE, "test:"+(++i).toString());
        context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
        appsData.put(SAppsDatabase.COL_APP_TITLE, "test:"+(++i).toString());
        context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
        appsData.put(SAppsDatabase.COL_APP_TITLE, "test:"+(++i).toString());
        context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
        appsData.put(SAppsDatabase.COL_APP_TITLE, "test:"+(++i).toString());
        context.getContentResolver().insert(SuperAppsOrganizerProvider.CONTENT_URI, appsData);
        */
    }
}
